<!--
 * @Description:
 * @Author: charles
 * @Date: 2021-12-14 22:14:55
 * @LastEditors: charles
 * @LastEditTime: 2021-12-14 22:14:56
-->
<template>
  <div>
    <el-row>
      <el-col :span="6" style="padding-right:.5em;border-right:2px solid #f4f4f4">
        <el-tree :data="eds" :props="defaultProps" @node-click="handleNodeClick" />
      </el-col>
      <el-col :span="18">
        <div v-if="params.device_id" align="center">(无)</div>
        <div v-else style="line-height:3em;color:red;text-align:center">请选择设备</div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { get } from '@/utils/request'
export default {
  // 变量
  data() {
    return {
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      eds: [],
      params: {}
    }
  },
  // 页面加载完毕后执行
  mounted() {
    this.loadEngineerDevices()
  },
  // 方法
  methods: {
    handleNodeClick(node) {
      if (node.engineer_id) {
        // 点击了设备
        this.$set(this.params, 'engineer_id', node.engineer_id)
        this.$set(this.params, 'device_id', node.id)
      }
    },
    // 加载工程设备树
    loadEngineerDevices() {
      const url = '/engineer/findEngineerDeviceTree'
      get(url).then(resp => {
        this.eds = resp.data
      })
    }
  }
}
</script>
